package com.yixin.hospital.controller;

import com.yixin.hospital.common.ApiResult;
import com.yixin.hospital.common.Constant;
import com.yixin.hospital.entity.dto.req.purchaseorder.GoDownDrugReqDTO;
import com.yixin.hospital.entity.vo.GoDownDrugVo;
import com.yixin.hospital.entity.vo.PurchaseOrderDetailVO;
import com.yixin.hospital.service.GodownDrugService;
import com.yixin.hospital.utils.JwtUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

@RestController
@RequestMapping("/input-godown")
@Api(value = "入库单管理", tags = "入库单管理")
public class InputGodownController {

    @Resource
    private GodownDrugService godownDrugService;


    @GetMapping("/list2")
    @ApiOperation(value = "入库单列表")
    public ApiResult<?> list(HttpServletRequest request, @RequestParam int currentPage, @RequestParam int pageSize) {
        return godownDrugService.allList(request, currentPage, pageSize);
    }

    @GetMapping("/listInfo")
    @ApiOperation(value = "入库单详情")
    public ApiResult<?> ListInfo(@RequestParam String code) {
        return godownDrugService.listInfo(code);
    }

    @GetMapping("/detail")
    @ApiOperation(value = "入库单详情")
    public ApiResult<PurchaseOrderDetailVO> detail(@RequestParam int id, @RequestParam int deptId) {
        return godownDrugService.detail(id, deptId);
    }

    @PostMapping("/godown-drug2")
    @ApiOperation(value = "预入库")
    @Transactional
    public ApiResult<?> goDownDrug2(@Valid @RequestBody GoDownDrugReqDTO goDownDrugReqDTO, HttpServletRequest request) {
        String userName = JwtUtil.getName(request.getHeader(Constant.AUTHORIZATION));
        return godownDrugService.goDownDrug2(goDownDrugReqDTO, userName);
    }

    @PostMapping("/godown-costPrice")
    @ApiOperation(value = "填进价入库")
    @Transactional
    public ApiResult<?> goDownDrug2(@Valid @RequestBody GoDownDrugVo goDownDrug, HttpServletRequest request) {
        String userName = JwtUtil.getName(request.getHeader(Constant.AUTHORIZATION));
        return godownDrugService.goDownCostPrice(goDownDrug, userName);
    }


}
